const _mapping = {}

// 状态mapping
_mapping.status = function(val){
  let mapping = {0: '待配置', 1: '已上架', 2: '已下架'}
  let s = mapping[val]
  return s
}

// 时间补零
function add0(m){
  return m < 10 ? '0' + m : m
}
_mapping.date_format = function(shijianchuo){
  //shijianchuo是整数，否则要parseInt转换
  var time = new Date(shijianchuo)
  var y = time.getFullYear()
  var m = time.getMonth() + 1
  var d = time.getDate()
  var h = time.getHours()
  var mm = time.getMinutes()
  var s = time.getSeconds()
  return y + '-'+add0(m) + '-'+add0(d) + ' '+add0(h) + ':'+add0(mm) + ':' + add0(s)
}

_mapping.date_format2 = function(shijianchuo){
  //shijianchuo是整数，否则要parseInt转换
  var time = new Date(shijianchuo)
  var y = time.getFullYear()
  var m = time.getMonth() + 1
  var d = time.getDate()
  return y + '-'+add0(m) + '-'+add0(d)
}

_mapping.isNaN = function(num){
  if(isNaN(num)){
    return '--'
  }else{
    return num
  }
}

module.exports = _mapping